Assembly languages are commonly used for programming network processors. An assembly language is considered a second generation language (2GL) because it is just one step up from the native language of the hardware, called machine language, which is a set of instructions in the form of combinations of ones and zeros. An assembly language provides an instruction mnemonic, usually three letters long, corresponding to each machine instruction.
For a description of an exemplary architecture and the related instruction set, see U.S. Pat. No. 6,330,584 granted to Joffe, et al. on December 11, and entitled “Systems and methods for multi-tasking, resource sharing and execution of computer instructions” that is incorporated by reference herein in its entirety as background.
Since each different type of network processor uses a different native instruction set, assembly languages cannot be standardized from one manufacturer to another. Moreover, assembly languages normally provide no support for data abstraction and instead are primarily machine-level specific. For this reason, the source code for an assembly language is cryptic and in a very low machine-specific form.
For example, an instruction to test a bit which resides in a register file differs from the instruction to test a bit which resides in a channel register. Moreover, such an instruction can differ depending on the data type being operated on, i.e. the instruction for moving a byte differs from the instruction to move a word, even if they are in the same resource. The specific instruction set itself can differ depending on the network processor and a resource can have different characteristics depending on the network processor accessing the resource. As another example, instruction syntax can differ for bit operations versus byte/word/doubleword/longword operations. For example, to set bit 8 in register R0—0 of the register file to zero, the following assembly command is issued:                bitci R0—0, R0—0, #08, 0whereas setting byte 0 in register R0 to zero requires        move R0—0, zero, #BBBNot only is the instruction syntax different for bit fields, but there are a limited number of instructions or operations that can be performed on a bit field. For instance, the move instruction is not supported, nor is the compare instruction.        
Also, instruction syntax differs for each type of operation (Byte/word/doubleword/longword) as the size of the operand fields must be specified in the instruction. For instance, the move instruction is in the form of:                move opC, opB, sizewhere size specifies the size of opC and of opB. The programmer is forced to be aware of the size of each operand field and must also be careful not to use invalid size combinations. The same applies to other instructions such as compare. To move a zero into a byte field beginning at R0—0, the instruction is:        move R0—0, zero, #BBBTo move zero into a word beginning at R0—0 the instruction is:        move R0—0, zero, #WWW        
Note that #BBB and #WWW are normally translated to their corresponding constants.
The instructions also differ if the source operand is immediate data (i.e. is a value hard-coded into the instruction itself verses a value taken from a resource location). For instance, there are 3 versions of the compare instruction:    1) compare            cmp opC, opB, size            2) compare immediate byte            cpib opC, mask, imm            3) compare immediate word            cpiw opC, imm, sizeAll of these differences make it difficult to change data field definitions. For instance, changing a data record field from a byte to a word would require every line of code which accesses that data field to be modified accordingly. Typically, the programmer must develop macros for each field and the operation to be perform on it. This minimizes the amount of code that would have to change if a field definition is changed.        
As mentioned above, the network processor instructions can differ based on the resource being used. Each network processor resource has its own unique characteristics and influences on the instruction set syntax as well as the instructions supported. The programmer must be aware of these differences when developing code. For example, the Register File resource behaves much differently than the Channel Register resource. When setting bits, the Register File can only set a bit within a byte wide field so the programmer must determine which specific byte field to access, and then which corresponding bit within that byte to set. For instance, assume we have a 32-bit wide bit field containing various state flags and we want to set bit 10. Assuming that this 32-bit wide field resided in the register file starting at R0—0, the instruction would be:                bitci R0—2, R0—2, #2, 1The programmer had to know that it mapped to bit 2 in byte 3. If this same field existed in a Channel Register, the instruction would be:        bitci CR0, CR0, #10, 1Also, these resources behave differently when moving data fields. When a byte is moved into a Channel Register resource, the upper bytes are cleared. This forces the programmer to write specialized code when moving data into a Channel Register resource so as not to change the other data. For instance, assume there is a 4 byte data structure and we wish to set the low order byte to a value stored in register R7—0 of the register file without effecting any of the other data in the data structure. If the data structure started at R3—0 in the Register File, the code would be:        move R3—3, R7—0, #BBBIf the data structure was stored in Channel Register 0, the code would be:        move R0—0, CR0, #DDD        move R0—3, R7—0, #BBB        move CR0, R0—0, #DDDIf we wanted to extract byte 2 from the data structure and store it in R7—0, the code for the Register File would be:        move R7—0, R3—1, #BBBand for the Channel Register it would be:        shli R7—0, CR0, #8, #BBBIn this case, the programmer must know the size of the data structure field in order to specify the correct number of bits to shift.        